// Tags: DFS
#include <cstdio>

const int N = 100;
int n, map[N][N];

void dfs(int x, int y) {
  
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("P1312 Mayan游戏.in", "r", stdin);
  freopen("P1312 Mayan游戏.out", "w", stdout);
#endif
#endif

  scanf("%d", &n);
  for (int i = 1, j; i <= 5; ++i) {
    j = 0;
    while (scanf("%d", &map[i][++j]) != EOF && map[i][j] != 0) {}
  }
  dfs(0,0);
  return 0;
}